#include<bits/stdc++.h>
#define ll long long
using namespace std;
double d[100001],u[100001],a[100001],x[100001],h[100001];
ll n,m,th[100001],ans;
vector<int>q[100001];
bool check(int mid){
//	cout<<1<<" ";
	int t=1;
	for(int i=1;i<=m;i++){
		t=1;
		for(int j=0;j<q[i].size();j++){
			if(th[q[i][j]]==1){
				t=0;
				break;
			}
		}
		if(t){
			ans++;
			for(int j=0;j<q[i].size();j++) th[q[i][j]]--;
		}
	}
	if(ans>=mid) return 1;
	return 0;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int k,l,v,t;
	cin>>k;
	while(k){
		memset(h,0,sizeof(h));
		ans=0;
		for(int i=1;i<=m;i++) q[i].clear();
		cin>>n>>m>>l>>v;
		for(int i=1;i<=n;i++){
			cin>>d[i]>>u[i]>>a[i];
		}
		for(int i=1;i<=m;i++){
//			cout<<i<<":";
			cin>>x[i];
			for(int j=1;j<=n;j++){
				if(d[j]>x[i]) continue;
				t=ceil(sqrt(u[j]*u[j]+2*a[j]*(x[i]-d[j])-1));
				if(t>v){
					if(!h[j]){
						ans++;
//						cout<<j<<" ";
					}
					h[j]++;
					q[i].push_back(j);
//					cout<<j<<" ";
				}
			}
//			cout<<endl;
		}
		cout<<ans<<" ";
/*
		for(int i=1;i<=n;i++)  cout<<h[i]<<" ";
		cout<<endl;
		for(int i=1;i<=m;i++){
			cout<<i<<':';
			for(int j=0;j<q[i].size();j++) cout<<q[i][j]<<" ";
			cout<<endl;
		}
*/
		ll l=1,r=m,mid;
		while(l<=r){
			ans=0;
			for(int i=1;i<=n;i++) th[i]=h[i];
			mid=(l+r)/2;
			if(check(mid)) l=mid+1;
			else r=mid-1;
		}
		cout<<l-1<<endl;
		k--;
	}
	return 0;
}
